/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.cacheplugins  
 */
package com.apache.bid.service.cacheplugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.common.vo.BidItemCacheVo;
import com.apache.bid.entity.BidItem;
import com.apache.bid.entity.BidSession;
import com.apache.bid.manager.BidItemManager;
import com.apache.cache.util.Validator;

/**
 * description:  串行时查找一下个开始的标的修订
 * @author Hou Dayu 创建时间：2016-5-17  
 * 
 */
public class NextItemPluginImpl implements PluginConnector {

	private BidItemManager bidItemManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("item");
		String itemId = String.valueOf(param.getParams("itemId"));
		String sessionId = String.valueOf(param.getParams("sessionId"));
		BidSession session = (BidSession) cache.getCacheObjectByKey(cache.session_prefix + sessionId);
		ResultEntity entity = new ResultEntity();
		if (!Validator.isEmpty(session) && "T".equals(session.getSerialCtrl())) {//是否串行
			BidItemCacheVo itemVo = (BidItemCacheVo) cache.getCacheCloneByKey(cache.item_prefix + itemId);
			ParamsVo<BidItem> vo = new ParamsVo<BidItem>();
			vo.setObj(itemVo);
			vo.setKey("nextItemBySeId");
			BidItem item = (BidItem) bidItemManager.execute(vo);
			entity.setEntity(item);
		}
		entity.setResult("true");
		entity.setMessage("查询成功");
		return entity;
	}

	public void setBidItemManager(BidItemManager bidItemManager) {
		this.bidItemManager = bidItemManager;
	}

}
